#include "AppConfig.h"
#include <QSettings>
#include <QCoreApplication>

QString AppConfig::s_filepath;


AppConfig::AppConfig()
{

}

QString AppConfig::getFilePath()
{
	return s_filepath;
}

void AppConfig::setFilePath(const std::string& filepath)
{
	s_filepath = filepath.c_str();
}

bool AppConfig::get(const QString& key, QString& value)
{
    QString fileName = getFilePath();
	if (fileName.isEmpty())
	{
		return false;
	}

    QSettings settings(fileName, QSettings::IniFormat);
    settings.setIniCodec("utf-8");
    if (!settings.contains(key))
    {
        return false;
    }

    value = settings.value(key).toString();
    return true;
}

bool AppConfig::set(const QString& key, const QString& value)
{
    QString fileName = getFilePath();
	if (fileName.isEmpty())
	{
		return false;
	}

    QSettings settings(fileName, QSettings::IniFormat);
    settings.setValue(key, value);
    return true;
}
